# -*- coding: UTF-8 -*-

from qiniu import Auth, put_file, etag
import time

# 文件上传
does_not_exist = 4
more_then_2 = 3
file_exsit = 2
ok = 1

ak = '-Oa6lz6oazBF2aibyAF4_qSvh7P8XziW13HGeVzQ'
sk = 'a8KwBberev1jilm35HFLrFOaa2uJma1n7XSpCRjz'


def uploadFile(filename, path):
    q = Auth(ak, sk)
    # 要上传的空间
    bucket_name = 'cr-public'

    filePath = path + "/" + filename

    end = str(int(time.time())) + "_" + filename
    # 上传后保存的文件名
    key = "park/fileFile/stz/lhxy/" + end
    print(key)

    # 生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    # 要上传文件的本地路径

    print(token)

    ret, info = put_file(token, key, filePath, version='v2')
    print(ret['key'])

    print(info)

    assert ret['key'] == key
    return key


uploadFile('a.txt', '/Users/lixianhe/Downloads')
